<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet"/>
    <link th:href="@{/css/index.css}" rel="stylesheet"/>
    <link th:href="@{/css/tool.css}" rel="stylesheet"/>
    <!-- 图标  -->
    <link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_1531710_xb357ub1wmg.css"/>
    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
    <script th:src="@{/js/marked.min.js}" type="text/javascript"></script>
</head>
<body>
<div th:each="zbInfo : ${zbInfos}">
    <input type="hidden" th:value="${#dates.format(zbInfo.openTime,'yyyy-MM-dd HH:mm:ss')}" id="openTime">
</div>
<div class="layui-fluid main">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-lg9" id="zbhx">
            <h1>中标候选人</h1>
            <hr>
            <table id="scoring" lay-filter="test"></table>
        </div>

        <div class="layui-col-lg3">
            <h1>小提醒</h1>
            <hr>
            <h3>1.注意此界面展示的是专家评选后推荐的中标候选人。
                <br>
                2.评标人需要注意
                <span style="color: #FD482C">一个招标项目只能选择一个投标人作为中标</span></span></h3>

        </div>
    </div>
</div>

</body>
<script id="select" type="text/html">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="select">确认中标人</a>
</script>
<script>
    layui.config({base: '/js/'}).extend({
        tableMerge: 'tableMerge'
    });

    layui.use(['table', 'jquery', 'layer', 'util', 'tableMerge', 'element'], function () {
        var table = layui.table,
            $ = layui.jquery,
            layer = layui.layer,
            util = layui.util,
            element = layui.element,
            tableMerge = layui.tableMerge;

        var endTime = new Date($('#openTime').val())//结束日期
            , serverTime = new Date().getTime(); //假设为当前服务器时间，这里采用的是本地时间，实际使用一般是取服务端的

        console.log(endTime)
         if (endTime <= serverTime) {

            var tableId = table.render({
                elem: '#scoring',
                url: '/score/scoreTotal',
                height: 312,
                page: true,
                skin: 'col', //行边框风格
                cols: [
                    [{type: 'numbers', title: '序号', width: 100, fixed: 'left', align: 'center'},
                        {
                            field: 'd.tbInfo.projectId',
                            title: '投标编号',
                            align: 'center',
                            templet: "<div>{{d.tbInfo.projectId}}</div>"
                        },
                        {
                            field: 'd.zbInfo.title',
                            title: '招标项目名称',
                            align: 'center',
                            // merge: true,
                            templet: "<div>{{d.zbInfo.title}}</div>"
                        },
                        {field: 'pf', title: '评分', align: 'center', sort: true, width: 80, style: "color:#009688"},
                        {fixed: 'right', title: '操作', width: 210, align: 'center', toolbar: '#select'}
                    ]
                ],
                done: function (res) {
                    tableMerge.render(this)
                }
            });
            table.on('tool(test)', function (obj) {

                var count=0;
                if (obj.event === "select") {
                    if(count==0){
                        $.ajax({
                            type: 'post',
                            url: '/publish_apply',
                            data: {
                                zbId: obj.data.zbInfo.id,
                                tbId: obj.data.tbInfo.id
                            },
                            success: function (res) {
                                if (res.code == 200) {
                                    count++;
                                    layer.msg('已确认该招标项目的中标人');

                                }else if(res.code == 500){
                                    layer.msg('已经确认过了，等待管理员审核之后,发布公告');
                                }
                            }
                        })
                    }else if(count>0){
                        layer.msg("已经挑选过中标人")
                    }
                }
            })
         }else{
             $('#zbhx').append("<span>还未到开标时间，暂无数据</span>")
         }


    })
</script>
</html>